﻿Public Class VACCINEICDCLASS
    Private VICDID As Integer = Nothing
    Private VACCINEID As Integer = Nothing
    Private ICDID As Integer = Nothing
    Private STATUS = Nothing
    Private SelectMasvaccineicd = Nothing
    Dim connect As CONDB = CONDB.NewConnection()
    Property SelectMasvaccineicd_() As String
        Get
            SelectMasvaccineicd = "SELECT `vicdid`,masvaccine.`vaccineid`,masvaccine.`vaccine_th` as 'วัคซีน',masdiagcode.`icdid`,masdiagcode.`icddesc_th` as 'ชื่อรหัสโรคภาษาไทย',masvaccineicd.`status` as 'สถานะการเปิดใช้งาน'"
            SelectMasvaccineicd += "FROM masvaccineicd "
            SelectMasvaccineicd += "LEFT JOIN (SELECT `vaccineid`,`vaccine_th` FROM masvaccine WHERE `status` = 1) AS masvaccine on masvaccineicd.`vaccineid` = masvaccine.`vaccineid` "
            SelectMasvaccineicd += "LEFT JOIN (SELECT `icdid`,`icddesc_th` FROM masdiagcode WHERE `status` = 1) AS masdiagcode on masvaccineicd.`icdid` = masdiagcode.`icdid` "
            Return SelectMasvaccineicd
        End Get
        Set(value As String)

        End Set
    End Property
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    Property ICDID_() As Integer
        Get
            Return ICDID
        End Get
        Set(value As Integer)
            ICDID = value
        End Set
    End Property
    Property VACCINEID_() As Integer
        Get
            Return VACCINEID
        End Get
        Set(value As Integer)
            VACCINEID = value
        End Set
    End Property
    Property VICDID_() As Integer
        Get
            Return VICDID
        End Get
        Set(value As Integer)
            VICDID = value
        End Set
    End Property
    Public Sub insertVaccineicdData()
        Try
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            Dim Sql As String
            Sql = "INSERT INTO masvaccineicd "
            Sql += "(`vaccineid`,`icdid`,`status`) "
            Sql += " VALUES ("
            Sql += "'" & VACCINEID & "',"
            Sql += "'" & ICDID & "',"
            Sql += "'" & STATUS & "')"
            connect.ExecuteNonQuery(Sql)
            connect.CommitTrans()
            MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
        'End If
    End Sub
    Public Sub editVaccineicddata()
        connect = CONDB.NewConnection()
        connect.BeginTrans()
        Try
            Dim sql As String
            sql = "UPDATE masvaccineicd SET `status` = '" & STATUS & "',"
            If ICDID = 0 Then
                sql += "`icdid` = Null"
            Else
                sql += "`icdid` = '" & ICDID & "'"
            End If
            If VACCINEID = 0 Then
                sql += "`vaccineid` = Null"
            Else
                sql += "`vaccineid` = '" & VACCINEID & "'"
            End If
            sql += "WHERE `vicdid` = '" & VICDID & "'"
            connect.ExecuteNonQuery(sql)
            connect.CommitTrans()
            MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
    End Sub
End Class
